/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.markers;

import deatax.Player;
import deatax.display.Model;
import deatax.display.ModelLoader;
import deatax.display.Texture;
import java.io.FileNotFoundException;
import java.util.HashMap;
import javax.media.opengl.GL2;

/**
 *
 * @author Caroline
 */
public class UnitMarker extends Marker {

    public static HashMap<String, Model> modelCache = new HashMap<String, Model>();
    public Model model;
    public int count = 1;

    public UnitMarker(Player p, String type) {
        super(p);
        if (modelCache.containsKey(type)) {
            model = modelCache.get(type);
        } else {
            try {
                //System.out.println("trying to load: " + "markers/" + type + ".obj");
                model = ModelLoader.loadModel("markers/" + type + ".obj");
                if (model != null) {
                    if (Texture.loadImage("markers/" + type + ".png") != null) {
                        model.setTexture(new Texture("markers/" + type + ".png"));
                        modelCache.put(type, model);
                    }
                }
            } catch (FileNotFoundException ex) {
                model = null;
            }
        }
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Override
    public void drawP1(GL2 gl) {
        if (count == 0) {
            return;
        }
        for (int i = 0; i < count; i++) {
            gl.glTranslatef(0, 0, 0.04f);
            drawBase(gl);
        }

        model.draw(gl);
        gl.glTranslatef(0, 0, -0.04f * count);
    }
}
